Spot-On
libspoton.h
1 /*
2 ** Copyright (c) 2011 - 10^10^10, Alexis Megas.
3 ** All rights reserved.
4 **
5 ** Redistribution and use in source and binary forms, with or without
6 ** modification, are permitted provided that the following conditions
7 ** are met:
8 ** 1. Redistributions of source code must retain the above copyright
9 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
13 ** 3. The name of the author may not be used to endorse or promote products
14 ** derived from Spot-On without specific prior written permission.
15 **
16 ** SPOT-ON IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 ** SPOT-ON, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef LIBSPOTON_H
29 #define LIBSPOTON_H
30 
31 #define LIBSPOTON_VERSION 0x000106
32 #define LIBSPOTON_VERSION_STR "0.1.6"
33 
34 #ifdef LIBSPOTON_OS_WINDOWS
35 #include "errno.h"
36 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
37 #include "gcrypt.h"
38 #pragma GCC diagnostic warning "-Wdeprecated-declarations"
39 #include "pthread.h"
40 #include "sqlite3.h"
41 #else
42 #include <errno.h>
43 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
44 #include <gcrypt.h>
45 #pragma GCC diagnostic warning "-Wdeprecated-declarations"
46 #include <pthread.h>
47 #include <sqlite3.h>
48 #endif
49 #include <stdbool.h>
50 #include <stdint.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <string.h>
54 
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59 
60 typedef enum
61  {
62  LIBSPOTON_ERROR_NONE = 0,
63  LIBSPOTON_ERROR_CALLOC,
64  LIBSPOTON_ERROR_GCRY_CALLOC,
65  LIBSPOTON_ERROR_GCRY_CALLOC_SECURE,
66  LIBSPOTON_ERROR_GCRY_CHECK_VERSION,
67  LIBSPOTON_ERROR_GCRY_CIPHER_ENCRYPT,
68  LIBSPOTON_ERROR_GCRY_CIPHER_GET_ALGO_BLKLEN,
69  LIBSPOTON_ERROR_GCRY_CIPHER_GET_ALGO_KEYLEN,
70  LIBSPOTON_ERROR_GCRY_CIPHER_MAP_NAME,
71  LIBSPOTON_ERROR_GCRY_CIPHER_OPEN,
72  LIBSPOTON_ERROR_GCRY_CIPHER_SETIV,
73  LIBSPOTON_ERROR_GCRY_CIPHER_SETKEY,
74  LIBSPOTON_ERROR_GCRY_CONTROL,
75  LIBSPOTON_ERROR_GCRY_KDF_DERIVE,
76  LIBSPOTON_ERROR_GCRY_MD_MAP_NAME,
77  LIBSPOTON_ERROR_INVALID_LENGTH,
78  LIBSPOTON_ERROR_INVALID_PARAMETER,
79  LIBSPOTON_ERROR_KERNEL_PROCESS_ALREADY_REGISTERED,
80  LIBSPOTON_ERROR_NOT_CONNECTED_TO_SQLITE_DATABASE,
81  LIBSPOTON_ERROR_NULL_LIBSPOTON_HANDLE,
82  LIBSPOTON_ERROR_NUMERIC_ERROR,
83  LIBSPOTON_ERROR_SQLITE_BIND_BLOB_CONTENT,
84  LIBSPOTON_ERROR_SQLITE_BIND_BLOB_DESCRIPTION,
85  LIBSPOTON_ERROR_SQLITE_BIND_BLOB_TITLE,
86  LIBSPOTON_ERROR_SQLITE_BIND_BLOB_URL,
87  LIBSPOTON_ERROR_SQLITE_BIND_INT,
88  LIBSPOTON_ERROR_SQLITE_BIND_INT64,
89  LIBSPOTON_ERROR_SQLITE_BIND_INT_ENCRYPT,
90  LIBSPOTON_ERROR_SQLITE_CREATE_KERNEL_REGISTRATION_TABLE,
91  LIBSPOTON_ERROR_SQLITE_CREATE_KERNEL_REGISTRATION_TRIGGER,
92  LIBSPOTON_ERROR_SQLITE_CREATE_URLS_TABLE,
93  LIBSPOTON_ERROR_SQLITE_DATABASE_LOCKED,
94  LIBSPOTON_ERROR_SQLITE_OPEN_V2,
95  LIBSPOTON_ERROR_SQLITE_PREPARE_V2,
96  LIBSPOTON_ERROR_SQLITE_STEP
97  }
98 libspoton_error_code_t;
99 
101 {
102  char *m_key;
103  int m_cipherAlgorithm;
104  size_t m_keyLength;
105  sqlite3 *m_sqliteHandle;
106 };
107 
108 typedef libspoton_error_code_t libspoton_error_t;
109 typedef struct libspoton_handle_struct_t libspoton_handle_t;
110 
111 /*
112 ** Is a kernel process registered?
113 */
114 
115 bool libspoton_is_kernel_registered(libspoton_handle_t *libspotonHandle,
116  libspoton_error_t *error);
117 
118 /*
119 ** Return a user-friendly string representation of error.
120 */
121 
122 const char *libspoton_strerror(const libspoton_error_t error);
123 
124 libspoton_error_t libspoton_create_urls_table
125 (libspoton_handle_t *libspotonHandle);
126 
127 /*
128 ** Delete URLs.
129 */
130 
131 libspoton_error_t libspoton_delete_urls(libspoton_handle_t *libspotonHandle,
132  const int encrypted);
133 
134 /*
135 ** Deregister the kernel process.
136 */
137 
138 libspoton_error_t libspoton_deregister_kernel
139 (const pid_t pid, libspoton_handle_t *libspotonHandle);
140 
141 /*
142 ** Create shared.db. Initialize containers.
143 */
144 
145 libspoton_error_t libspoton_init_a(const char *databasePath,
146  const char *cipherType,
147  const char *key,
148  const size_t keyLength,
149  libspoton_handle_t *libspotonHandle,
150  const int secure_memory_pool_size);
151 libspoton_error_t libspoton_init_b(const char *databasePath,
152  const char *cipherType,
153  const char *hashType,
154  const char *passphrase,
155  const char *salt,
156  const size_t passphraseLength,
157  const size_t saltLength,
158  const unsigned long iterationCount,
159  libspoton_handle_t *libspotonHandle,
160  const int secure_memory_pool_size);
161 
162 /*
163 ** Register a kernel process.
164 */
165 
166 libspoton_error_t libspoton_register_kernel
167 (const pid_t pid,
168  const bool forceRegistration,
169  libspoton_handle_t *libspotonHandle);
170 
171 /*
172 ** Encode the content, description, title, and url via cipherType and
173 ** place the encoded values into the urls table. The url field is required
174 ** while content, description, and title may be 0.
175 ** Please note that the passphrase must agree with the passphrase
176 ** understood by Spot-On.
177 */
178 
179 libspoton_error_t libspoton_save_url(const char *url,
180  const size_t urlSize,
181  const char *title,
182  const size_t titleSize,
183  const char *description,
184  const size_t descriptionSize,
185  const char *content,
186  const size_t contentSize,
187  libspoton_handle_t *libspotonHandle);
188 
189 /*
190 ** Retrieve the registered kernel's PID.
191 */
192 
193 pid_t libspoton_registered_kernel_pid(libspoton_handle_t *libspotonHandle,
194  libspoton_error_t *error);
195 
196 /*
197 ** Release resources and reset important containers to zero.
198 */
199 
200 void libspoton_close(libspoton_handle_t *libspotonHandle);
201 void libspoton_enable_sqlite_cache(void);
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 #endif
Definition: libspoton.h:100